import axios from 'axios'
import {message} from 'antd'

export default function ajax(url, data={}, method='GET'){
	return new Promise((resolve, reject)=>{
		let promise
		if(method==='GET'){
			promise = axios.get(url, {params:data})
		}else{
			promise = axios.post(url, data)
		}

		promise.then(response=>{
			//如果成功了，调用resolve()
			resolve(response.data)
		}).catch((error)=>{
			//如果失败了，不调用reject(),而是提示异常信息
			message.error('请求出错了：' + error.message)
		})
	})
}